﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using AutoMapper;
using BaseAPI.BaseController;
using BaseAPI.BaseViewModel;
using Microsoft.AspNetCore.Mvc;
using Snowflake.Core;
using WebTest.Models;
using WebTest.ViewModels.ProjectViewModel;

namespace WebTest.Controllers;

/// <summary>
/// 项目
/// </summary>
[ApiController]
[Route("[controller]/[action]")]
public class ProjectController(DataContext dataContext, IMapper mapper, IdWorker idWorker)
    : BaseController<Project>(dataContext, mapper, idWorker)
{
    /// <summary>
    /// 添加项目
    /// </summary>
    /// <param name="projectCreateRequest"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<string>> Create(ProjectCreateRequest projectCreateRequest)
    {
        return await Z_Create(projectCreateRequest);
    }

    /// <summary>
    /// 批量添加项目
    /// </summary>
    /// <param name="projectCreateRequests"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<List<string>>> BatchCreate(List<ProjectCreateRequest> projectCreateRequests)
    {
        return await Z_Create(projectCreateRequests);
    }

    /// <summary>
    /// 获取项目列表
    /// </summary>
    /// <param name="baseGetListViewModel"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<List<Project>>> GetList(BaseGetListViewModel<Project> baseGetListViewModel)
    {
        return await Z_GetList(baseGetListViewModel);
    }

    /// <summary>
    /// 获取项目列表使用名称模糊查询
    /// </summary>
    /// <param name="projectGetListByNameRequest"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<List<Project>>> GetListByName(ProjectGetListByNameRequest projectGetListByNameRequest)
    {
        return await Z_GetList(projectGetListByNameRequest);
    }

    /// <summary>
    /// 获取项目列表（转换）
    /// </summary>
    /// <param name="baseGetListViewModel"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<List<ProjectGetListResponse>>> GetListAndTrans(BaseGetListViewModel<Project,ProjectGetListResponse> baseGetListViewModel)
    {
        return await Z_GetList(baseGetListViewModel);
    }

    /// <summary>
    /// 获取项目列表使用名称模糊查询并转换
    /// </summary>
    /// <param name="projectGetListRequest"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<List<ProjectGetListResponse>>> GetListByNameAndTrans (ProjectGetListByNameAndTransRequest projectGetListRequest)
    {
        return await Z_GetList(projectGetListRequest);
    }

    /// <summary>
    /// 获取项目（使用ID）
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ResponseModel<Project>> GetOneByID([Required] long ID)
    {
        return await Z_GetOne(ID);
    }

    /// <summary>
    /// 获取项目（使用搜索函数搜索，按名称模糊匹配）
    /// </summary>
    /// <param name="projectGetOneByNameRequest"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<Project>> GetOneByName(ProjectGetOneByNameRequest projectGetOneByNameRequest)
    {
        return await Z_GetOne(projectGetOneByNameRequest);
    }

    /// <summary>
    /// 获取项目（使用ID和自动转换函数）
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<ProjectGetListResponse>> GetOneByIDAndTrans([Required] long ID)
    {
        return await Z_GetOne<ProjectGetListResponse>(ID);
    }

    /// <summary>
    /// 获取项目（使用搜索函数和转换函数）
    /// </summary>
    /// <param name="getOneByNameAndTrans"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<ProjectGetListResponse>> GetOneByNameAndTrans(ProjectGetOneByNameAndTransRequest getOneByNameAndTrans)
    {
        return await Z_GetOne(getOneByNameAndTrans);
    }

    /// <summary>
    /// 修改项目（部分修改，前端指定修改字段）
    /// </summary>
    /// <param name="projectPatchRequest"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<int>> ModifyPatch(ProjectPatchRequest projectPatchRequest)
    {
        return await Z_Modify(projectPatchRequest);
    }

    /// <summary>
    /// 修改项目（全部修改）
    /// </summary>
    /// <param name="project"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<int>> ModifyPut(Project project)
    {
        return await Z_Modify(project);
    }

    /// <summary>
    /// 批量修改项目（部分修改，前端指定修改字段）
    /// </summary>
    /// <param name="projectPatchRequests"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<int>> BatchModifyPatch(List<ProjectPatchRequest> projectPatchRequests)
    {
        return await Z_Modify(projectPatchRequests);
    }

    /// <summary>
    /// 批量修改项目（全部修改）
    /// </summary>
    /// <param name="projects"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<int>> BatchModifyPut(List<Project> projects)
    {
        return await Z_Modify(projects);
    }

    /// <summary>
    /// 删除项目
    /// </summary>
    /// <param name="ID">ID</param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ResponseModel<int>> Delete([Required] long ID)
    {
        return await Z_Delete(ID);
    }

    /// <summary>
    /// 批量删除项目
    /// </summary>
    /// <param name="IDs">ID数组</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ResponseModel<int>> BatchDelete([Required] List<long> IDs)
    {
        return await Z_Delete(IDs);
    }
}